package com.ajk.server.dao;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ajk.server.dao.provider.DoctorProvider;
import com.ajk.server.model.Doctor;
import com.ajk.server.model.query.DoctorQuery;
import com.ajk.server.model.response.DoctorRes;
/**
 * 医生  <br>
 * t_doctor <br>
 * v1.0 2016-05-07
 */
 public interface DoctorMapper {
 	
 	/**
 	*根据id删除 医生
 	*/
 	@Delete("delete from t_doctor where id=#{id}")
 	public Integer deleteById(Integer id);
 	
 	/**
 	* 批量新增 医生
 	*/
 	@InsertProvider(method="batchInsert",type=DoctorProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
 	public Integer batchInsert(List<? extends Doctor> doctors);
 	
 	/**
 	* 新增 医生
 	*/
 	@InsertProvider(method="insert",type=DoctorProvider.class)
	@Options(useGeneratedKeys=true)
 	public Integer insert(Doctor domain);
 
 	
 	/**
 	*更新 医生
 	*/
 	@UpdateProvider(method="update",type=DoctorProvider.class)
 	public Integer update(Doctor domain);
 	
 	/**
 	*根据ID查询 医生
 	*/
	@Select("select * from t_doctor where id=#{id}")
	public DoctorRes findById(Integer id);
	
	/**
 	*通过query 查询 医生
 	*/
 	@SelectProvider(method="findByQuery",type=DoctorProvider.class)
 	public List<DoctorRes> findByQuery(DoctorQuery query);
 	
 	/**
 	*通过query count总条数
 	*/
 	@SelectProvider(method="countByQuery",type=DoctorProvider.class)
 	public Integer countByQuery(DoctorQuery query);
 	
 	/**
 	* 通过ids查询
 	*/
 	@SelectProvider(method="findByUserIds",type=DoctorProvider.class)
 	public List<DoctorRes> findByUserIds(List<Integer> userIds);
 	
	@Select("select * from t_doctor where user_id=#{userId}")
	public DoctorRes findByUserId(Integer userId);
 	
	@Select("select a.*,d.name,c.id pd_id,e.name title_name from t_doctor a,dict_department b,dict_department c,t_users d,dict_doctor_title e where"
			+ "		a.department_id = b.id and b.parent_id = c.id and a.user_id = d.id and a.title_id = e.id and c.parent_id = 0 and hospital_id = #{hospitalId}")
	public List<DoctorRes> findDoctorForHospitalId(Integer hospitalId);

}	